/**
cache实列现方式1：使用Map做为数据存储，增加sync.Mutex锁 使cache存储居有原子性，同一时间只能对
缓存Map进行单操作
*/
package gocache

import "sync"


//例用内存Map实现简单缓存
type  cacheEntity struct {
	lk    *sync.Mutex
	store map[string]interface{}
}

var cache *cacheEntity

func init() {
	cache = new(cacheEntity)
	cache.lk = new(sync.Mutex)
	cache.store = make(map[string]interface{})
}
func AddCache(key string, value interface{}) {
	cache.lk.Lock()
	defer cache.lk.Unlock()
	cache.store[key] = value
}
func GetCache(key string) (value interface{}) {
	cache.lk.Lock()
	defer cache.lk.Unlock()
	if value, ok := cache.store[key]; ok {
		return value
	}
	return nil
}

//从缓存中移除数据
func RemoveCache(key string) {
	cache.lk.Lock()
	defer cache.lk.Unlock()
	delete(cache.store, key)
}

